package org.deng.vertx.springboot.web.controller;

import io.vertx.core.Vertx;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.ext.auth.jwt.JWTAuth;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.handler.JWTAuthHandler;
import org.apache.tools.ant.Project;
import org.deng.vertx.springboot.config.ProjectProperties;
import org.deng.vertx.springboot.util.FastJsonUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author 邓力宾
 * @date 2022/12/29 9:42
 * @desc
 */
public abstract class BaseController implements RouterController{
    @Autowired
    protected  Vertx vertx;
    @Autowired
    protected JWTAuth jwtAuth;
    @Autowired
    protected JWTAuthHandler jwtAuthHandler;

    @Autowired
    protected ProjectProperties projectProperties;


    protected void writeJSON(RoutingContext ctx, Object o){
        HttpServerResponse response = ctx.request().response();
        response.headers().set("Content-Type", "application/json;charset:utf-8");
        ctx.end(FastJsonUtils.toJSONString(o));
    }

    protected String getParam(RoutingContext context, String name){
        List<String> values = context.queryParam(name);
        if(values == null || values.isEmpty()){
            return  null;
        }
        return values.get(0);
    }
    protected List<String> getParamList(RoutingContext context, String name){
        return context.queryParam(name);
    }

}
